<?php require_once ("header.php"); ?>
<?php 
	if ($ad_check==0 && $user_check==0){
		header ("Location:error.php?code=406");
	}
?>
<?php 
	$sql_get_user="SELECT * FROM student WHERE stud_no='$id'";
	$get_user=mysql_query($sql_get_user);
	$user=mysql_fetch_assoc($get_user);
	$dep=$user['stud_deparment'];
	$course=$user['stud_course'];
	$sem=$user['stud_sem'];
	$class=$user['class'];
	
	$sql_get_row="SELECT quiz_id FROM quiz WHERE quiz_course='$course' AND quiz_sem='$sem' AND quiz_class='$class' AND quiz_department='$dep'";
	$get_row=mysql_query($sql_get_row);
	$num_row=mysql_num_rows($get_row);
?>
<?php
	//setting page limit and pagination variable
	
	$limit=20;
	if (isset($_GET['id'])){
		$data=$_GET['id'];
	} else {
		$data=0;
	}
	$total_page=intval($num_row/$limit);
	$temp = $num_row-($total_page*$limit);
	if ($temp > 0 ) { 
		$total_page++;
	}
	if ($data>$num_row) {
		echo "<center>cannot process your request.  Your request exceed the amount of data in database.</center>";
		exit();
	}
	//get current page
	$current=intval(($data+$limit)/$limit);
	
	//set the previous and next link to be valid or not.
	if ($data<1) {
		$previous=0; // previous link is invalid
	} else {
		$previous=1; // previous link is valid
	}
	if (($num_row-$data)<=$limit) {
		$next=0;  // next link is invalid
	} else {
		$next=1;  // next link is valid
	}
		
?>
<style type="text/css">
<!--
.style3 {font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style4 {color: #000000}
-->
</style>

<table width="780" height="24" border="0" align="center">
  <tr>
    <td width="193" height="20"><span class="style4">List result <?php echo $data+1; ?> -
      <?php 
		if (($num_row < $limit) || (($num_row-$data)<$limit)) { 
			echo $num_row; 
		} else { 
			echo ($data+$limit); 
		} 
	?>
    </span></td>
    <td width="188"><span class="style4"></span></td>
    <td width="94"><span class="style4"></span></td>
    <td width="287"><div align="right" class="style4">
      <?php if ($previous==1) {
			echo "<a href=\"page.php?id=" .($data-$limit)."\">Previous</a>";
		} else { ?>
      
      <?php } ?>
      | Page <?php echo $current; ?> |
      <?php if ($next==1) {
			echo "<a href=\"page.php?id=" .($data+$limit)."\">Next</a>";
		} else { ?>
      
      <?php } ?>
    </div></td>
  </tr>
</table>
<table width="780" border="0" align="center">
  <tr bordercolor="#FFFFFF" bgcolor="#333333">
    <td width="71"><div align="center"><span class="style3">CLASS</span></div></td>
    <td width="201"><div align="center"><span class="style3">LECTURER</span></div></td>
    <td width="140"><div align="center"><span class="style3">START</span></div></td>
    <td width="139"><div align="center"><span class="style3">END</span></div></td>
    <td width="104"><div align="center"><span class="style3">QUIZ NUMBER </span></div></td>
    <td width="99"><div align="center"><span class="style3">ACTION</span></div></td>
  </tr>
  <?php 
  	//get all quizes which is valid to student
	$sql_get_quiz="SELECT * FROM quiz WHERE quiz_course='$course' AND quiz_sem='$sem' AND quiz_class='$class' AND quiz_department='$dep' ORDER BY quiz_number ASC";
	$get_quiz=mysql_query($sql_get_quiz);
	$get_date=mysql_query($sql_get_quiz);
	$sql_get_subject="SELECT quiz_subject FROM quiz_question WHERE quiz_course='$course' AND quiz_sem='$sem' AND quiz_class='$class' AND quiz_department='$dep'";
  	
	
	$g=mysql_fetch_assoc($get_date);
  	$start=$g['quiz_start'];
  	$end=$g['quiz_end'];
  	$today=date('Y-m-d H:i:s');
  ?>
  <?php while ($q=mysql_fetch_assoc($get_quiz)) { 
  			$start=$q['quiz_start'];
			$end=$q['quiz_end'];
			$today=date('Y-m-d H:i:s');
  			if ($today >= $start && $today <= $end)
			{ ?>
  <tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
    <td><div align="center"><span class="style4">
      <?php $a="{$course} {$sem}{$class}"; echo $a; ?>
    </span></div></td>
    <td><span class="style4">
      <?php $sql_get_name="SELECT ad_name FROM admin WHERE ad_no='{$q['ad_id']}'";
			  $get_name=mysql_query($sql_get_name);
			  $name=mysql_fetch_assoc($get_name);
			  $name=$name['ad_name'];
			  echo $name; ?>
    </span>	</td>
    <td><div align="center"><span class="style4"><?php echo $q['quiz_start']; ?></span></div></td>
    <td><div align="center" class="style4"><?php echo $q['quiz_end']; ?></div></td>
    <td><div align="center" class="style4"><?php echo $q['quiz_number']; ?></div></td>
    <td><div align="center"><span class="style4"><?php echo "<a href=\"quiz.php?key={$q['quiz_number']}&&key2={$q['quiz_subject']}\">Take Quiz</a>"; ?></span></div></td>
  </tr>
  <?php } else {} }?>
</table>
<table width="780" height="24" border="0" align="center">
  <tr>
    <td width="193" height="20"><span class="style4">List result <?php echo $data+1; ?> -
      <?php 
		if (($num_row < $limit) || (($num_row-$data)<$limit)) { 
			echo $num_row; 
		} else { 
			echo ($data+$limit); 
		} 
	?>
    </span></td>
    <td width="188"><span class="style4"></span></td>
    <td width="94"><span class="style4"></span></td>
    <td width="287"><div align="right" class="style4">
      <?php if ($previous==1) {
			echo "<a href=\"page.php?id=" .($data-$limit)."\">Previous</a>";
		} else { ?>
      
      <?php } ?>
      | Page <?php echo $current; ?> |
      <?php if ($next==1) {
			echo "<a href=\"page.php?id=" .($data+$limit)."\">Next</a>";
		} else { ?>
      
      <?php } ?>
    </div></td>
  </tr>
</table>
<p>&nbsp;</p>
